package com.dlc.shop.multishop.controller;

import com.dlc.shop.bean.dto.ShopBranchCode;
import com.dlc.shop.service.ShopBranchCodeService;

import jakarta.validation.Valid;

import com.dlc.shop.common.response.ServerResponseEntity;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dlc.shop.common.util.PageParam;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;


/**
 * 银行支行字典表
 * @author liyong
 */
@RestController
@RequestMapping("/shopBank/shopBranchCode")
@Tag(name = "银行支行字典表")
@AllArgsConstructor
public class ShopBranchCodeController {

    private final ShopBranchCodeService shopBranchCodeService;

    @GetMapping("/page")
    @Operation(summary = "获取银行支行字典表列表", description = "分页获取银行支行字典表列表")
    public ServerResponseEntity<List<ShopBranchCode>> getShopBranchCodePage(ShopBranchCode shopBranchCode) {
        return ServerResponseEntity.success(shopBranchCodeService.list(new LambdaQueryWrapper<ShopBranchCode>()
                .eq(ShopBranchCode::getBankCode,shopBranchCode.getBankCode())
                .like(ShopBranchCode::getBranchName,shopBranchCode.getBranchName())));
    }

    @GetMapping("/info/{branchCode}")
    @Operation(summary = "获取银行支行字典表", description = "根据branchCode获取银行支行字典表")
    @Parameter(name = "branchCode", description = "银行支行字典表", required = true)
    public ServerResponseEntity<ShopBranchCode> getById(@PathVariable("branchCode") String branchCode) {
        return ServerResponseEntity.success(shopBranchCodeService.getById(branchCode));
    }

    @PostMapping
    @Operation(summary = "保存银行支行字典表", description = "保存银行支行字典表")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid ShopBranchCode shopBranchCode) {
        return ServerResponseEntity.success(shopBranchCodeService.save(shopBranchCode));
    }

    @PutMapping
    @Operation(summary = "更新银行支行字典表", description = "更新银行支行字典表")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ShopBranchCode shopBranchCode) {
        return ServerResponseEntity.success(shopBranchCodeService.updateById(shopBranchCode));
    }

    @DeleteMapping("/{branchCode}")
    @Operation(summary = "删除银行支行字典表", description = "根据银行支行字典表id删除银行支行字典表")
    @Parameter(name = "branchCode", description = "银行支行字典表", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable String branchCode) {
        return ServerResponseEntity.success(shopBranchCodeService.removeById(branchCode));
    }
}
